package com.example.bleuesprit.parkAndroidClient;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.bleuesprit.parkAndroidClient.net.NetUtil;

import org.json.JSONException;
import org.json.JSONObject;

public class ForgetPassWordActivity extends Activity {



    EditText forgetEmail_ET;
    Button forgetSubmit_Bnt;



    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0x123) {
                // 登录信息返回结果
                Log.i("ForgetPassWordActivity",msg.getData().getString("result"));
                try {
                    JSONObject jsonObject=new JSONObject(msg.getData().getString("result"));

                    //Toast.makeText(LoginActivity.this, jsonObject.getString("result"), Toast.LENGTH_LONG).show();
                    if( jsonObject.getString("findResult").equals("accept"))
                    {

                        Toast.makeText(ForgetPassWordActivity.this,"邮件已发送",Toast.LENGTH_LONG).show();
                        return;
                    }
                    else if(jsonObject.getString("findResult").equals("none"))
                    {
                        Toast.makeText(ForgetPassWordActivity.this,"没有找到邮箱",Toast.LENGTH_LONG).show();

                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_forget_pass_word);
        forgetSubmit_Bnt=(Button)findViewById(R.id.forgetPassWord_forget_btn);
        forgetEmail_ET=(EditText)findViewById(R.id.forgetPassWord_email);

        forgetSubmit_Bnt.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        doForgetPassWord(v);
                    }
                }
        );

    }




    void doForgetPassWord(View v)
    {
        JSONObject loginMessage=new JSONObject();
        try {

            loginMessage.put("email", forgetEmail_ET.getText().toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        NetUtil.sendToServer("forgetPassWord", loginMessage, handler);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {


        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        return id == R.id.action_settings || super.onOptionsItemSelected(item);
    }

}

